package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.rank.UnionRank;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross.group.CrossGroupProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manager.union.CrossUnionRankMgr;
import com.yanqu.road.server.manager.union.unionrank.CrossUnionRankMsgCacheMgr;
import com.yanqu.road.server.manger.ServerGroupMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CROSS_UNION_GROUP_RANK_TOP, desc = "分组榜单榜首数据,榜单跨服过来商会跨服组装")
public class CrossServerGroupRankTopCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        RankProto.RankTopOneRespMsg.Builder rankTopOneRespMsg = RankProto.RankTopOneRespMsg.parseFrom(packet.getBytes()).toBuilder();
        //商会榜首
        RankProto.UnionRankListMsg unionListMsg = CrossUnionRankMsgCacheMgr.getUnionCrossRankMsgByGroupId(rankTopOneRespMsg.getGroupId());
        if (unionListMsg == null) {
            log.error("CrossServerGroupRankTopCmd execute unionCrossRankMsgByGroupId is null. groupId:{}", rankTopOneRespMsg.getGroupId());
            return;
        }

        if (null != unionListMsg && unionListMsg.getRankListCount() > 0) {
            rankTopOneRespMsg.setUnionRankTop(unionListMsg.getRankList(0));
        }

        YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.U_GROUP_RANK_TOP, rankTopOneRespMsg);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }

    @Override
    public void sendData() {

    }
}
